package me.a04dolydemo4;

public class Test {
    public static void main(String[] args) {
        Person p1 = new Person("老王", 20);
        Person p2 = new Person("老李", 21);
        Dog d = new Dog("黄色", 1);
        Cat c = new Cat("黑色", 2);
        p1.keepPet(d, "骨头");
        p2.keepPet(c, "鱼");
    }
}

class Animal {
    private String color;
    private int age;

    public Animal() {
    }

    public Animal(String color, int age) {
        this.color = color;
        this.age = age;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void eat(String something) {
        System.out.println("动物吃" + something);
    }
}

class Dog extends Animal {
    public Dog() {
    }

    public Dog(String color, int age) {
        super(color, age);
    }

    public void lookhome() {
        System.out.println("狗看家");
    }
}

class Cat extends Animal {
    public Cat() {
    }

    public Cat(String color, int age) {
        super(color, age);
    }

    public void catchMouse() {
        System.out.println("猫捉老鼠");
    }
}

class Person {
    private String name;
    private int age;

    public Person() {
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void keepPet(Dog d, String something) {
        System.out.println("年龄为" + age + "的老王养了一只" + d.getColor() + d.getAge() + "的狗" + "狗在吃" + something);
    }

    public void keepPet(Cat c, String something) {
        System.out.println("年龄为" + age + "的老李养了一只" + c.getColor() + c.getAge() + "的猫" + "猫在吃" + something);
    }
}


